package cn.edu.tju.ldj.analytics.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.tju.ldj.analytics.Const;
import cn.edu.tju.ldj.analytics.Factory;

public class ContractDetailServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String ctrctid;
	private String alphaid;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		try {
			doMethod(request, response);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		try {
			doMethod(request, response);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	private void doMethod(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		setCtrctid(request.getParameter(Const.PARAM_FILE_SECTION_REQ_CTRCTID));
		if(getCtrctid() == null){
			setCtrctid((String)request.getSession().getAttribute(Const.PARAM_FILE_SECTION_REQ_CTRCTID));
		}
		setAlphaid(request.getParameter("alphaid"));
		System.out.println(getAlphaid());
		System.out.println(getCtrctid());
		request.getSession().setAttribute(Const.PARAM_FILE_SECTION_REQ_CTRCTID, getCtrctid());
		request.getSession().setAttribute("alphaLst", Factory.utilParam.getAlphaLst(getAlphaid()));
		
		request.getSession().setAttribute("contractName", Factory.servGood.getContractDetailById(getCtrctid()));
		response.sendRedirect(Factory.utilParam.getParam(Const.PARAM_FILE_SECTION_PAGE_CTDTAILST));
	}

	public String getCtrctid() {
		return ctrctid;
	}

	public void setCtrctid(String ctrctid) {
		this.ctrctid = ctrctid;
	}
	
	public String getAlphaid() {
		return alphaid;
	}

	public void setAlphaid(String alphaid) {
		this.alphaid = alphaid;
	}
	
}
